package cn.project.lemontree.controller;

import cn.project.lemontree.aop.SystemControllerLog;
import cn.project.lemontree.bean.Child;
import cn.project.lemontree.bean.Parent;
import cn.project.lemontree.bean.User;
import cn.project.lemontree.bean.Video;
import cn.project.lemontree.dao.VideoDao;
import cn.project.lemontree.service.VideoService;
import cn.project.lemontree.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/video")
@Api(tags = "视频管理模块")
@CrossOrigin  //跨域访问
public class VideoController {
    @Resource
    private VideoService videoService;
    @Resource
    private VideoDao videoDao;

    @ApiOperation("分页查询视频信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="page",value="页码",required=true,dataTypeClass = int.class,example = "1"),
            @ApiImplicitParam(name="size",value="每页行数",required=true,dataTypeClass = int.class,example = "10"),
            @ApiImplicitParam(name="theme",value="主题",required=false,dataTypeClass = String.class)
    })
    @GetMapping("/listpage")
    public CommonResult<Map<String, Object>> listpage(int page,int size,String theme){
        Map<String ,Object> map = new HashMap<>();
        map.put("data",videoService.listpage(page,size,theme));
        map.put("count",videoService.count(theme));
        map.put("page",page);
        return CommonResult.success(map);
    }

    @SystemControllerLog(description = "删除视频")
    @ApiOperation("删除视频信息")
    @PostMapping("/remove")
    public CommonResult remove(int video_id){
        return CommonResult.success(videoService.removeById(video_id));
    }

    @SystemControllerLog(description = "上传视频")
    @ApiOperation("上传视频")
    @PostMapping("/save")
    public CommonResult save(@RequestParam("file") MultipartFile file, Integer childId,Integer parentId,String theme,String ddesc){
        Video video = new Video(theme,ddesc,new Child(childId),new Parent(parentId));
        return CommonResult.success(videoService.save(file,video));
    }

}
